﻿using Pfz.Threading.Unsafe;

namespace Pfz.RemoteGaming
{
	/// <summary>
	/// This is the class that should be inherited to create threaded animations.
	/// You must handle it through the ThreadedAnimation safe class.
	/// </summary>
	public abstract class UnsafeThreadedAnimation:
		UnsafeThreadedIterator
	{
		/// <summary>
		/// Catches the RemoteGameObjectDisposedException and class the OnAnimate.
		/// </summary>
		protected sealed override void OnRun()
		{
			try
			{
				OnAnimate();
			}
			catch(RemoteGameObjectDisposedException)
			{
			}
		}

		/// <summary>
		/// Must be implemented to do the animation.
		/// </summary>
		protected abstract void OnAnimate();
	}
}
